﻿@{
    ViewBag.Title = "模具档案编辑";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<link href="~/Content/css/common.css" rel="stylesheet" />
<link href="~/Content/css/MouldArchiveAdd.css" rel="stylesheet" />
<script type="text/javascript">
    $(function () {
        Index.init();
    });

    var Index = {
        jsonData:@Html.Raw(ViewData["jsonData"].ToString()),
        init: function () {
            with (Index) {
                initControl();
                
                $.renderMy97Datepicker();
                //新增则不加载数据
                !!Index.jsonData && loadData();

                $('select').bindSelect();
            }
        },
        initControl: function () {
            var template = $("#butnAdd").html(),obj={val:"新增",icon:"plus"};

            !!Index.jsonData && (function () {
                obj={val:"修改",icon:"edit"};
            })();

            $("#butnAdd").html(template.format(obj));

            $("#butnReturn").on("click",function(){
                !!$.request("page") && !!$.request("idx") &&(function(page,idx){
                    location.href = "/BaseData/MouldArchive/MouldArchiveManagement?page={0}&idx={1}".format(page,idx);
                })($.request("page"),$.request("idx"));
            });

           
            //产权单位
            $("#RightUnit").bindSelect({
                url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
                id: "UnitNO",
                text: "UnitNOShortName"
            });
            //项目单位
            $("#ManuUnit").bindSelect({
                url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
                id: "UnitNO",
                text: "UnitNOShortName"
            });
            //制造单位
            $("#ProjectUnit").bindSelect({
                url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
                id: "UnitNO",
                text: "UnitNOShortName"
            });
            //模具类别
            $(".ModCategory").bindSelect({
                url: "/Mould/MouldArchive/GetModCategories?FClassNO=23",
                id: "FTypeNO",
                text: "FTypeNOName"
            });
            //模具产品类别
            $(".ModProductCategory").bindSelect({
                url: "/Mould/MouldArchive/GetModCategories?FClassNO=24",
                id: "FTypeNO",
                text: "FTypeNOName"
            });
            //使用单位
            $("#MoldUnit").bindSelect({
                url: "/Mould/MouldArchive/GetUseUnits",
                id: "MakeLineNO",
                text: "MakeLineNOMakeLineShortName"
            });
            //使用车间
            $("#MoldWorkshop").bindSelect({
                url: "/Mould/MouldArchive/GetUseUnits",
                id: "MakeLineNO",
                text: "MakeLineNOMakeLineShortName"
            });

            $("#butnGoVehicleDistr").on("click", function () {
                var url = "/Mould/MouldArchive/MouldArchiveUnits";
                
                $.modalOpen({
                    id:"dlgVehicleDist",
                    url: url,
                    width: "1200px",
                    height: "600px",
                    close: true,
                    callBack: function (id) {
                        cols = "VehicleDistr".split(",");
                         
                        var dests = "FProductNO".split(","), jsonData = {},i=0;

                        dests.forEach(function (item) {
                            $("#{0}".format(cols[i++])).val(parent.parent.$("#{0}".format(id)).find("iframe").contents().find("#{0}".format(item)).val());
                        });
                    }
                });
            });

            $("#butnShareProduction").on("click", function () {
                var url = "/Mould/MouldArchive/MouldArchivePartNumbers";
                
                $.modalOpen({
                    id:"dlgShareProduction",
                    url: url,
                    width: "1200px",
                    height: "600px",
                    close: true,
                    callBack: function (id) {
                        cols = "MoldProductionNO".split(",");
                         
                        var dests = "FProductionNO".split(","), jsonData = {},i=0;

                        dests.forEach(function (item) {
                            $("#{0}".format(cols[i++])).val(parent.parent.$("#{0}".format(id)).find("iframe").contents().find("#{0}".format(item)).val());
                        });
                    }
                });
            });
            $("#butnGoPartNumbers").on("click", function () {
                var url = "/Mould/MouldArchive/MouldArchivePartNumbers";
                
                $.modalOpen({
                    id:"dlgPartNumbers",
                    url: url,
                    width: "1200px",
                    height: "600px",
                    close: true,
                    callBack: function (id) {
                        cols = "WorkpieceNo,WorkpieceName".split(",");
                         
                        var dests = "FProductionNO,FProductionName".split(","), jsonData = {},i=0;

                        dests.forEach(function (item) {
                            $("#{0}".format(cols[i++])).val(parent.parent.$("#{0}".format(id)).find("iframe").contents().find("#{0}".format(item)).val());
                        });
                    }
                });
            });

            $("#butnAdd").on("click",function(){
                //有值则表示修改
                Index.jsonData && (function(){
                    Index.validateToControl($(".required_c input,.required_c select").toArray(),/^\S+$/ig,"此项为必填项！","error_input") & 
                    Index.validateToControl($(".input_c_numeric input").toArray(),/^0$|^[1-9]\d*\.\d*$|^0\.\d*[1-9]\d*$|(^[1-9]\d*$)/ig,"只容许输入数字！","error_input") &&
                    Index.add("修改");
                })();
                //空值则表示新增
                Index.jsonData || (function(){
                    Index.validateToControl($(".required_c input,.required_c select").toArray(),/^\S+$/ig,"此项为必填项！","error_input") & 
                    Index.validateToControl($(".input_c_numeric input").toArray(),/^0$|^[1-9]\d*\.\d*$|^0\.\d*[1-9]\d*$|(^[1-9]\d*$)/ig,"只容许输入数字！","error_input") &&
                    Index.add("添加");
                })();
            });
        },
        loadData: function () {
            Index.jsonData["InputUserFUpdateBy"] = "{0} {1}".format(Index.jsonData["InputUser"],Index.jsonData["FUpdateBy"]);

            Index.jsonData["InputDateInputTimeFUpdateDateFUpdateTime"] 
                = "{0} {1}/{2} {3}".format(Index.jsonData["InputDate"],
                                                        Index.jsonData["InputTime"],
                                                        Index.jsonData["FUpdateDate"],
                                                        Index.jsonData["FUpdateTime"]
                                                        );

            $("[name=CopyMold]").each(function(){
                $(this).prop("checked",  $(this).val()==Index.jsonData["CopyMold"]);
            });

            for(var idx in Index.jsonData){
                $("#{0}".format(idx)).val(Index.jsonData[idx]);
            }
        },
        validateToControl:function(cs,regular,errMsg,errInfoCls){
            var template = "<div class=\"err_msg_c\"> <div class=\"err_msg_icon\"></div> <div class=\"err_msg\">{0}</div> </div>";
            cs.forEach(function(item){
                regular.lastIndex = 0;
                var foo = regular.test($.trim($(item).val()));
                foo || (function(cur){
                    cur.addClass(errInfoCls);

                    !cur.parents(".input_c").find(".err_msg_c").length &&  
                    cur.parents(".input_c").append(template.format(errMsg));
                })($(item));

                foo && (function(cur){
                    cur.removeClass(errInfoCls);

                    cur.parents(".input_c").find(".err_msg_c").remove();
                    
                })($(item));
            });
            //如果所有控件验证正确则len为0
            return !$(".error_input").length;
        },
        add:function(tips){
            var cols = "Moldid,RegistrationDate,MoldNO,MoldName,WorkpieceNo,WorkpieceName,ProcessNO,AssetsNO,MoldNum,MoldLife,MoldSize,CloseHeight,MoldWeight,TopWeight,MoldProductionNO,MoldCategory,MoldType,TransDate,TransValues,RightUnit,PutDate,UsedPress,IsDisable,ManuUnit,VehicleDistr,MoldUnit,MoldWorkshop,MaintenCycle,RinseCycle,ProjectUnit,ProjectNo,MoldExplain".split(",");
            
            var obj = {};

            for(var idx in cols){
                obj[cols[idx]] = $("#{0}".format(cols[idx])).val();
            }

            obj["CopyMold"] = $("[name=CopyMold]:checked").val();

            var param = {param:JSON.stringify(obj)};

            $.post("/Mould/MouldArchive/UpdateMouldArchive",param,function(res){
                0 < res  && $.modalAlert("{0}成功！".format(tips), "success");
            },"json");
        }
    };



</script>
<div id="layout">
    <h1>请输入模具信息</h1>
    <div class="container">
        <ul class="form_list">
            <li class="form_item form_item_a">
                <h2 class="form_item_title">建档日期</h2>
                <div class="input_c input_c_short required_c">
                    <input id="RegistrationDate" name="" placeholder="" type="text" my97date="yyyy-MM-dd" class="form-control required" />
                </div>
                <div class="after">*</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">模具编号</h2>
                <div class="input_c input_c_normal required_c">
                    <input id="MoldNO" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="after">*</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">模具名称</h2>
                <div class="input_c required_c">
                    <input id="MoldName" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="after">*</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">制件编号</h2>
                <div class="input_c input_c_normal">
                    <input id="WorkpieceNo" readonly="readonly" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">
                    <button id="butnGoPartNumbers" class="butn_details glyphicon  glyphicon-search"></button>
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">制件名称</h2>
                <div class="input_c">
                    <input id="WorkpieceName" readonly="readonly" name="" placeholder="" type="text" class="form-control required" />
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">工序编号</h2>
                <div class="input_c input_c_normal">
                    <input id="ProcessNO" name="" placeholder="" type="text" class="form-control required" />
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">资产编号</h2>
                <div class="input_c input_c_normal">
                    <input id="AssetsNO" name="" placeholder="" type="text" class="form-control required" />
                </div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">模具数量</h2>
                <div class="input_c input_c_short input_c_numeric">
                    <input id="MoldNum" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">件</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">模具寿命</h2>
                <div class="input_c input_c_short input_c_numeric">
                    <input id="MoldLife" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">冲次</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">模具尺寸</h2>
                <div class="input_c input_c_short">
                    <input id="MoldSize" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">mm</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">闭合高度</h2>
                <div class="input_c input_c_short input_c_numeric">
                    <input id="CloseHeight" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">mm</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">模具重量</h2>
                <div class="input_c input_c_short input_c_numeric">
                    <input id="MoldWeight" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">吨</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">上模重量</h2>
                <div class="input_c input_c_short input_c_numeric">
                    <input id="TopWeight" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">吨</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">复制模具</h2>
                <div class="input_c input_c_short">
                    <input id="ra01" name="CopyMold" type="radio" value="0" checked="checked" /><label for="ra01">是</label>
                    <input id="ra02" name="CopyMold" type="radio" value="1" /><label for="ra02">否</label>
                </div>
                <div class="after">*</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">共用产品</h2>
                <div class="input_c input_c_normal">
                    <input id="MoldProductionNO" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">
                    <button id="butnShareProduction" class="butn_details glyphicon  glyphicon-search"></button>
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">模具类别</h2>
                <div class="input_c input_c_selected">
                    <select id="MoldCategory" class="sel_common ModCategory">
                        <option value="">请选择</option>
                    </select>
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">模具产品类型</h2>
                <div class="input_c input_c_selected">
                    <select id="MoldType" class="sel_common ModProductCategory">
                        <option value="">请选择</option>
                    </select>
                </div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">转固时间</h2>
                <div class="input_c input_c_short input_c_numeric">
                    <input id="TransDate" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">年</div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">转固原值</h2>
                <div class="input_c input_c_short input_c_numeric">
                    <input id="TransValues" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">元</div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">产权单位</h2>
                <div class="input_c input_c_selected">
                    <select id="RightUnit" class="sel_common ProductUnit">
                        <option value="">请选择</option>
                    </select>
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">投入使用日期</h2>
                <div class="input_c input_c_short">
                    <input id="PutDate" name="" placeholder="" my97date="yyyy-MM-dd" type="text" class="form-control required" />
                </div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">已使用冲次</h2>
                <div class="input_c input_c_short input_c_numeric">
                    <input id="UsedPress" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">冲次</div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">使用状态</h2>
                <div class="input_c input_c_selected">
                    <select id="IsDisable" class="sel_common">
                        <option value="0">在用</option>
                        <option value="1">停用</option>
                        <option value="2">闲置</option>
                        <option value="3">报废</option>
                    </select>
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">制造单位</h2>
                <div class="input_c input_c_selected">
                    <select id="ManuUnit" class="sel_common ProductUnit">
                    </select>
                </div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">产品车型分布</h2>
                <div class="input_c input_c_normal">
                    <input id="VehicleDistr" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="aftern">
                    <button id="butnGoVehicleDistr" class="butn_details glyphicon  glyphicon-search"></button>
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">使用单位</h2>
                <div class="input_c input_c_selected">
                    <select id="MoldUnit" class="sel_common">
                    </select>
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">使用车间</h2>
                <div class="input_c input_c_selected">
                    <select id="MoldWorkshop" class="sel_common">
                    </select>
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">保养周期</h2>
                <div class="input_c  input_c_short input_c_numeric">
                    <input id="MaintenCycle" name="" placeholder="" type="text" class="form-control required" />
                </div>
            </li>
            <li class="form_item form_item_a">
                <h2 class="form_item_title">维修周期</h2>
                <div class="input_c  input_c_short input_c_numeric">
                    <input id="RinseCycle" name="" placeholder="" type="text" class="form-control required" />
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">项目单位</h2>
                <div class="input_c input_c_selected">
                    <select id="ProjectUnit" class="sel_common">
                    </select>
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">项目编号</h2>
                <div class="input_c input_c_normal">
                    <input id="ProjectNo" name="" placeholder="" type="text" class="form-control required" />
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">备注说明</h2>
                <div class="input_c">
                    <input id="MoldExplain" name="" placeholder="" type="text" class="form-control required" />
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">操作人员</h2>
                <div class="input_c">
                    <input id="InputUserFUpdateBy" name="" placeholder="" type="text" class="form-control required" readonly="readonly" />
                </div>
            </li>
            <li class="form_item">
                <h2 class="form_item_title">输入日期</h2>
                <div class="input_c">
                    <input id="InputDateInputTimeFUpdateDateFUpdateTime" readonly="readonly" name="" placeholder="" type="text" class="form-control required" />
                </div>
            </li>
            <li class="clear"></li>
        </ul>
        <footer>
            <div class="btn-group">
                <a id="butnAdd" class="btn btn-primary center-block"><span class="glyphicon glyphicon-{icon}"></span>{val}</a>
                <a id="butnReturn" class="btn btn-primary center-block"><span class="glyphicon glyphicon-chevron-left"></span>返回</a>
                <input id="Moldid" type="hidden" />
            </div>
        </footer>
    </div>
</div>


